package com.ruoyi.gateway.filter;

import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 黑名单过滤器
 * @author ruoyi
 */
@Component
@Order(1)
public class BlackListUrlFilter extends OncePerRequestFilter {

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
                                    FilterChain filterChain) throws ServletException, IOException {

        CustomizeRequestWrapper requestWrapper = (request instanceof CustomizeRequestWrapper)
                ? (CustomizeRequestWrapper)request : new CustomizeRequestWrapper(request) ;

        filterChain.doFilter(requestWrapper , response);
    }
}
